package com.yangfei.SportAssistant.services;

import com.yangfei.SportAssistant.util.Constants;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class CGoogleLocationListener extends MapListsenerSuper {

	private LocationManager			locationManager;
	private LocationListener		mLocationListener	= null;
	private MapServiceInterface	mService			= null;

	public void Init(MapServiceInterface aService) {

		mService = aService;
		listsenerSelf = this;
		locationManager = (LocationManager) mService.GetContext()
				.getSystemService(Context.LOCATION_SERVICE);
		mapProviderName = Constants.GoogleMap;

		mLocationListener = new LocationListener() {
			@Override
			public void onLocationChanged(Location location) {
				mService.DoLocationChanged(location,listsenerSelf);
			}

			@Override
			public void onProviderDisabled(String provider) {
				// Do nothing
			}

			@Override
			public void onProviderEnabled(String provider) {
				// Do nothing
			}

			@Override
			public void onStatusChanged(String provider, int status,
					Bundle extras) {
				// Do nothing
			}
		};

	}

	public void StartListen(long minInterval, int minDistance) {
		locationManager.requestLocationUpdates(Constants.GPS_PROVIDER,
				minInterval, minDistance,
				// , 0 /* minDistance, get all updates to properly time pauses
				// */
				mLocationListener);
		
		ResetLocationFilter();
	}

	public void StopListen() {
		locationManager.removeUpdates(mLocationListener);
	}
	
	public boolean IsManagerReady()
	{
		if(locationManager == null)
			return false;
		else
			return true;
	}
	
	public void Destroy() {

	}

}
